import React from 'react';
import i18n from 'i18n-js';
import ModalSelect from '@/components/ModalSelect';

interface IState {
  visible: boolean;
  content: any;
  needsExpensive: boolean;
  confirm: any;
}

export default class SelectAppModalScreen extends React.Component<{}, IState> {

  state = {
    visible: false,
    content: [
    ],
    confirm: () => { },
  };

  componentDidMount() {
    global.selectAppModal = {
      show: this.show,
      hide: this.hide,
    };
  }

  show = async (content: any): Promise<void> => {
    return new Promise((res) => {
      this.setState({
        visible: true,
        content,
        confirm: (config: any) => {
          res(config);
          this.hide();
        },
      });
    });
  };

  hide = () => {
    this.setState({
      visible: false,
    });
  };

  render() {
    const {
      visible, content, confirm,
      // needsExpensive
    } = this.state;
    return (
      <ModalSelect
        onPress={confirm}
        title={i18n.t('SELECT_CONFIG_FILE')}
        visible={visible}
        content={content}
      />
    );
  }
}
